using B.S.XZYData.Api.Wrter.Application.Command.SalesOrder;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.XZYData.Api.Wrter.Controllers
{
    /// <summary>
    /// 销售订单控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class SalesOrderController : ControllerBase
    {
        private readonly IMediator _mediator;

        public SalesOrderController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 新增销售订单
        /// </summary>
        /// <param name="command">新增命令</param>
        /// <returns></returns>
        [HttpPost("AddSalesOrder")]
        public async Task<ApiResult<int>> AddSalesOrder([FromBody] AddSalesOrderCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 更新销售订单
        /// </summary>
        /// <param name="command">更新命令</param>
        /// <returns></returns>
        [HttpPost("UpdateSalesOrder")]
        public async Task<ApiResult<string>> UpdateSalesOrder([FromBody] UpdateSalesOrderCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 删除销售订单
        /// </summary>
        /// <param name="command">删除命令</param>
        /// <returns></returns>
        [HttpPost("DeleteSalesOrder")]
        public async Task<ApiResult<string>> DeleteSalesOrder([FromBody] DeleteSalesOrderCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
